home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Deutsche Edition 1
/
Deutsche Edition 1.iso
/
amok
/
amok_lha
/
amok58.lha
/
QSort
/
QSort.mod
< prev
next >
Wrap
Text File
|
1993-08-15
|
990b
|
40 lines
IMPLEMENTATION MODULE QSort;
(* TYPE GREATERTHAN = PROCEDURE(LONGINT, LONGINT): BOOLEAN;
* (echt größer)
*
* TYPE SWAP = PROCEDURE(LONGINT, LONGINT);
*)
PROCEDURE QSort(start, end: LONGINT;
gt: GREATERTHAN; swp: SWAP);
VAR i, j: LONGINT; (* Hilfszeiger *)
BEGIN (* QSort *)
IF start >= end THEN RETURN END;
(* Partitionierung *)
i := start + 1; j := end;
REPEAT
WHILE NOT(gt(i,start)) AND (i < end ) DO INC(i) END;
WHILE gt(j,start) AND (j > start + 1) DO DEC(j) END;
IF (i < j) THEN
swp(i,j); INC(i); DEC(j)
END
UNTIL j <= i;
IF (i = j) AND NOT(gt(i,start)) THEN INC(i) END;
IF i > end THEN swp(start, end); i := end END;
(* Ende der Partitionierugn *)
IF start < i-1 THEN QSort(start, i-1, gt, swp) END;
IF i < end THEN QSort( i, end, gt, swp) END
END QSort;
END QSort.def